package database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import bean.Grass;


public class Dao {

	private Logger log = Logger.getLogger(this.getClass());

	private Connection con = null;

	public Dao() {
		Bonecp bonecp = new Bonecp();
		con = bonecp.getConnection();
	}

	public void insert(ArrayList<Grass> list) {
		try {
			PreparedStatement ps = con
					.prepareStatement("insert into grass(text,href,img,site,md5) values(?,?,?,?,?)");
			for (Grass link : list) {
				ps.setString(1, link.getText());
				ps.setString(2, link.getHref());
				ps.setString(3, link.getImg());
				ps.setShort(4, (short) 1);
				ps.setString(5, link.getMd5());
				try {
					ps.execute();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e);
		}

	}

	public ResultSet select(String sql) {
		try{
			PreparedStatement ps = con.prepareStatement(sql);
			ResultSet rs=ps.executeQuery();
			return rs;
		}catch(Exception e){
			e.printStackTrace();
			log.error(e);
			return null;
		}
	}

	public void delete() {

	}

	public void update() {

	}
}
